package com.lzb.browser.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.browser.BaseAc;
import com.lzb.browser.Content;
import com.lzb.browser.HomeActivity;
import com.lzb.browser.R;
import com.lzb.browser.basic.utils.SPUtil;
import com.lzb.browser.databinding.ActivityInputPatternPswBinding;
import com.lzb.browser.view.PatternLockView;

public class InputPatternPswActivity extends BaseAc<ActivityInputPatternPswBinding> implements View.OnClickListener {


    @Override
    protected int onCreate() {
        return R.layout.activity_input_pattern_psw;
    }

    @Override
    protected void initView() {
        mDataBinding.tvUseBackupPassword.setOnClickListener(this);

        mDataBinding.patternLockView.setPatternLockViewListener(new PatternLockView.PatternLockViewListener() {
            @Override
            public void onLockEnd(int[] values) {
                String input = "";
                for (int value : values) {
                    input += value + "";
                }
                String password = SPUtil.getString(mContext, Content.myPassword, "");
                if (input.equals(password)) {
                    startActivity(HomeActivity.class);
                    finish();
                } else {
                    ToastUtils.showShort(getString(R.string.password_error));
                    mDataBinding.patternLockView.clearPattern();
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvUseBackupPassword) {//使用备用密码
            startActivity(InputBackupPswActivity.class);
        }
    }

    @Override
    protected void initData() {
        String password = SPUtil.getString(mContext, Content.myBackupPassword, "");
        if (TextUtils.isEmpty(password)) {
            mDataBinding.tvUseBackupPassword.setVisibility(View.GONE);
        }
    }
}